package com.sgb.kjwl.viewmodel.self.packers;


import com.sgb.kjwl.AppConstant;
import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.ShopTeamInfoEntity;
import com.sgb.kjwl.repository.HomeRepertory;
import com.sgb.kjwl.view.ui.fragment.packers.PersonIntroFragment;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;

import java.util.HashMap;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class PersonIntroModel extends BaseViewModel {
    private PersonIntroFragment fragment;

    public PersonIntroModel(PersonIntroFragment fragment, HomeRepertory repertory) {
        this.fragment = fragment;
    }

    public void getData(String shopId,String no, String channel) {
        //teamInfo:工队简介
        //engineerInfo:我的发布
        //teamPrice:工种报价
        //teamResult:施工业绩
        //teamMember:工队人员
        //equipment:自有设备
        Map<String, Object> map = new HashMap<>();
        map.put("userNo", shopId);
        map.put("no", no);
        map.put("channel", channel);
        map.put("page", 1);
        map.put("limit", AppConstant.PAGER_LIMIT);
        DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据获取中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getPackerAPI().queryTeamIntroByUser(map).enqueue(new Callback<BaseEntity<ShopTeamInfoEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<ShopTeamInfoEntity>> call, Response<BaseEntity<ShopTeamInfoEntity>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getState() == null) {
                    fragment.showEmpty();
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    fragment.updateViews(response.body().getData());
                } else {
                    MToast.showToast(fragment.getContext(), response.body().getMsg());
                    fragment.showEmpty();
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<ShopTeamInfoEntity>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
                fragment.showEmpty();
            }
        });
    }
}
